const splitargs = require('splitargs')

export default {
    // 执行命令
    exec(client, params) {
      return new Promise((resolve, reject) => {
        if (!client) {
            resolve('Redis Client Is Not Yet')
        }
        params = splitargs(params)
        const operation = params.shift()
        if (!operation || !client[operation]) {
            resolve('Command is undefined')
        }
        //执行redis命令
        client.send_command(operation, params, function (err, v) {
            if (err === null) {
                resolve(v)
            } else {
                reject(err)
            }
        })
      })
    },
    resolve(str){
       var result={};
       var resolveData=str.split("\r\n")
       var key="";
       var value={};
       for(var i=0;i<resolveData.length;i++){
           if(resolveData[i].indexOf('#')>=0 || resolveData[i].indexOf(":")<0){
               key=resolveData[i].replace('# ','');
               value={};
           }else{
               var k=resolveData[i].split(":")[0]
               var v=resolveData[i].split(":")[1]
               value[k]=v;
               result[key]=value;
           }
       }
       return result;
    }
}
